package kr.saeildamil.androidstudy_second.draw;

import java.util.Random;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class Ball {
	int x; //볼의 첫 터치했을 때 좌표
	int y; //볼의 첫 터치했을 때 좌표
	int rad; //볼의 반지름
	
	int dx; //볼의  이동방향  및 속도
	int dy; //볼의 이동방향 및 속도
	
	int color; //볼의 색
	int count; //벽에 부딪힌 횟수
	
	public Ball(int x, int y){
		Random rnd = new Random();
		this.x = x;
		this.y = y;
		this.rad = rnd.nextInt(26)+25;
		this.count = 0;
		this.color = Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
		do{
			this.dx = rnd.nextInt(11) - 5;
			this.dy = rnd.nextInt(11) - 5;
		}while(this.dx == 0 || this.dy == 0);
		
	}
	
	/*static Ball Create(int x, int y){
		Random rnd = new Random();
		Ball newBall = new Ball();
		
		newBall.x = x;
		newBall.y = y;
		newBall.rad = rnd.nextInt(26)+25;//볼의 사이즈 25-50
		
		do{
			newBall.dx = rnd.nextInt(11) - 5;
			newBall.dy = rnd.nextInt(11) - 5;
		}while(newBall.dx == 0 || newBall.dy == 0);
		
		newBall.count = 0;
		newBall.color = Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
		
		return newBall;
	}*/
	
	void Move(int Width, int Height){//화면사이즈를 매개변수로 받음
		x += dx;
		y += dy;
		
		if(x<rad || x>Width-rad){
			dx*= -1; //반대방향 전환
			count++; //벽에 부딪힌횟수 증수
		}
		
		if(y<rad || y>Height-rad){
			dy*=-1;
			count++;
		}
	}
	
	void Draw(Canvas canvas){
		Paint pnt = new Paint();
		pnt.setAntiAlias(true);
		
		for(int r=rad,alpha = 1; r>4; r--, alpha +=5){
			pnt.setColor(Color.argb(
					alpha, 
					Color.red(color), 
					Color.green(color), 
					Color.blue(color)));
			canvas.drawCircle(x, y, r, pnt);
		}
	}
}







